package com.lai.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lai.hospital.dto.AppointmentDTO;
import com.lai.hospital.dto.ConfirmAppointmentDTO;
import com.lai.hospital.dto.MedicalInfoDTO;
import com.lai.hospital.entity.Appointment;
import com.lai.hospital.enums.AppointmentStatusEnum;
import com.lai.hospital.service.AppointmentService;
import com.lai.hospital.vo.AppointmentVO;
import com.lai.hospital.vo.ConditionVO;
import com.lai.hospital.vo.PageResult;
import com.lai.hospital.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.controller
 * @Description: 预约控制器
 * @date Date : 2022年11月27日 23:48
 */
@RestController
@Api(value = "预约模块")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    /**
     * 根据患者id获取就诊信息列表
     * @param patientId 患者id
     * @return
     */
    @GetMapping("/user/listAppointmentByPatientId/{patientId}")
    @ApiOperation(value = "根据患者id获取就诊信息列表")
    @ApiImplicitParam(name = "patientId",value = "患者id",required = true,dataType = "Integer")
    public Result<List<MedicalInfoDTO>> listAppointmentByPatientId(@PathVariable("patientId") Integer patientId){
        return Result.ok(appointmentService.listAppointmentByPatientId(patientId));
    }


    /**
     * 后台获取预约列表
     * @param conditionVO 查询条件
     * @return
     */
    @GetMapping("/admin/listAppointment")
    @ApiOperation(value = "获取预约列表")
    public Result<PageResult<AppointmentDTO>> listAppointment(ConditionVO conditionVO){
        return Result.ok(appointmentService.listAppointment(conditionVO));
    }

    /**
     * 根据医生id获取预约列表 医生后台
     * @param conditionVO 查询条件
     * @return
     */
    @GetMapping("/admin/listAppointmentByDoctorId")
    @ApiOperation(value = "根据医生id获取预约列表")
    public Result<PageResult<AppointmentDTO>> listAppointmentByDoctorId(ConditionVO conditionVO){
        return Result.ok(appointmentService.listAppointmentByDoctorId(conditionVO));
    }
    /**
     * 删除预约信息
     * @param id 预约id
     * @return
     */
    @DeleteMapping("/admin/user/deleteAppointment/{id}")
    @ApiOperation(value = "删除预约信息")
    public Result<PageResult<AppointmentDTO>> deleteAppointment(@PathVariable("id") Integer id){
        appointmentService.deleteAppointment(id);
        return Result.ok();
    }


    /**
     * 根据患者id获取就诊信息列表
     * @param conditionVO 查询条件
     * @return
     */
    @GetMapping("/user/listAppointment")
    @ApiOperation(value = "根据用户id获取预约列表")
    public Result<List<AppointmentDTO>> listAppointmentByUserId(ConditionVO conditionVO){
        return Result.ok(appointmentService.listAppointmentByUserId(conditionVO));
    }

    /**
     * 取消预约
     * @param id 预约id
     * @return
     */
    @PutMapping("/user/cancelAppointment/{id}")
    @ApiOperation(value = "取消预约")
    @ApiImplicitParam(name = "id",value = "预约id",required = true,dataType = "Integer")
    public Result<?> cancelAppointment(@PathVariable("id") Integer id){
        appointmentService.cancelAppointment(id);
        return Result.ok();
    }

    /**
     * 用户预约
     * @return
     */
    @PostMapping("/user/saveAppointment")
    @ApiOperation(value = "用户预约")
    public Result<AppointmentVO> saveAppointment(@RequestBody AppointmentVO appointmentVO){
        return Result.ok(appointmentService.saveAppointment(appointmentVO));
    }

    /**
     * 根据id获取预约信息
     * @param id id
     * @return
     */
    @GetMapping("/user/appointment/{id}")
    @ApiOperation(value = "根据id获取预约信息")
    public Result<AppointmentDTO> getAppointmentById(@PathVariable Integer id){
        return Result.ok(appointmentService.getAppointmentById(id));
    }
}
